package com.kdx.wallet.controller;

import com.kdx.wallet.Constant;
import com.kdx.wallet.entity.Record;
import com.kdx.wallet.entity.dto.CommonResponses;
import com.kdx.wallet.service.RecordService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("record")
public class RecordController {
    @Resource
    private RecordService recordService;

    /**
     * 查询用户交易记录
     */
    @ResponseBody
    @RequestMapping("/{userId}")
    public CommonResponses<String> getTransactionRecords(@PathVariable Integer userId) {
        List<Record> records = recordService.getTransactionRecords(userId);
        if (records != null) {
            return new CommonResponses<>("success", Constant.SUCCESS_CODE, Constant.SUCCESS_MSG);
        }
        return new CommonResponses<>("failed",Constant.GET_TRANSACTION_RECORDS_FAILED_CODE,Constant.FAILED_MSG);
    }
}
